$(function () {
    layui.use(['table','layer'],function () {
        var table = layui.table;
        var layer = layui.layer;
        table.render({
            elem:'#list',
            url:'/pages/front/orderDe/list',
            totalRow: true, //开启合计行
            cols:[[
                {field: 'orid', title: '订单编号',sort: true, fixed: 'left',totalRowText:'合计:'},
                {field: 'number', title: '货物数量',sort: true, fixed: 'left'},
                {field: 'line', title: '运输线路'},
                {field:'title',title:'货物名称'},
                {
                    field: 'orderdate',
                    title: '创建日期',
                    templet: "<div>{{layui.util.toDateString(d.orderdate,'yyyy-MM-dd HH:mm:ss')}}</div>",
                    sort:true
                },
                {
                    field: 'delivery',
                    title: '运输时间',
                    templet: "<div>{{layui.util.toDateString(d.delivery,'yyyy-MM-dd HH:mm:ss')}}</div>",
                    sort:true
                },
                {field: 'price', title: '运输费用',totalRow:true,sort: true, fixed: 'left'},
                {field:'status',title:'状态',templet:'#status'},
                {field:'right',title:'操作',templet:"#barOption"},
                {field:'comment',title:'订单评价'},
            ]]
        })
        table.on('tool(list)',function (obj) {
            var data = obj.data;
            if(obj.event=="edit"){
                var orid = data.orid;
                var number =data.number;
                layer.open({
                    type:1,
                    title:'订单评价',
                    shade:0,
                    skin:'demo-class',
                    area: ['500px', '300px'],
                    content:
                    '<div class="layui-col-md10">' +
                    '<form class="layui-form" style="padding-top: 20px">'+
                    '<div class="layui-form-item">'+
                    '<label class="layui-form-label">输入文本</label>'+
                    ' <div class="layui-input-block">' +
                    '<textarea type="text" name="comment" required  lay-verify="required" placeholder="请输入您的评价" autocomplete="off" class="layui-input"></textarea>'+
                    '</div>'+
                    '</div>'+
                    '<div class="layui-form-item">' +
                    '<div class="layui-input-block">' +
                    '<input type="hidden" name="orid" value='+orid+'>' +
                    '<input type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-col-md-offset6"\n' +
                    '                                   lay-submit lay-filter="formDemo" id="editBtn" value="确认评价">\n' +
                    '                            <button type="reset" class="layui-btn layui-btn-danger layui-btn-sm">重置</button>' +
                    '</div>' +
                    '</div>' +
                    '</form>' +
                    '</div><div class="layui-col-md2">&nbsp;</div>'
                })
                $(function () {
                    $("#editBtn").on('click',function () {
                        $.ajax({
                            url:'/pages/front/orderDe/editOrderDe',
                            type:'post',
                            data:$('.layui-form').serialize(),
                            success:function (data) {
                                if(data=="success"){
                                    layer.msg("订单评价成功",{time:1000,icon:1,end:function () {
                                            window.location.href="/pages/front/orderDe/listPre"
                                        }})
                                }else if (data=="isEmpty"){
                                    layer.msg("数据有误",{time:1000,icon:2})
                                }else{
                                    layer.msg("订单评价失败",{time:1000,icon:2})
                                }
                            }
                        })
                    })
                })
            }

        })
    })
})